const URL = {

  // tabbar   
  home: "/pages/main/home/home",
  // cart: "pages/main/cart/cart",
  // activ: "pages/main/activ/activ",
  cate: "/pages/main/category/category",
  my: "/pages/main/my/my",

  // 商品
  detail: "/pages/product/detail/detail",
  confirm: "/pages/product/confirm/confirm",
  shops: "/pages/product/shops/shops",
  products: "/pages/product/products/products",

  // 订单
  order: "/pages/order/orderList/orderList",
  orderDetail: "/pages/order/orderDetail/orderDetail",
  renzheng: "/pages/order/renzheng/renzheng",
  express: "/pages/order/express/express",
  bill: "/pages/order/bill/bill",
  orderCancel: "/pages/order/orderCancel/orderCancel",
  orderBack: "/pages/order/orderBack/orderBack",

  // 用户
  authentication: "/pages/user/authentication/authentication", // 上传身份证
  enter: "/pages/user/enter/enter", // 商家入驻
  // 其他
  agreementList: "/pages/user/agreementList/agreementList", // 协议列表
  agreement: "/pages/user/agreement/agreement", // 购买协议
  userAuth: "/pages/user/userAuth/userAuth", // 用户授权
  userRegis: "/pages/user/userRegis/userRegis", // 注册协议
  userPriva: "/pages/user/userPriva/userPriva", // 用户隐私
  userCredit: "/pages/user/userCredit/userCredit", // 征信协议
  assurance: "/pages/user/assurance/assurance", // 征信协议
  arbitration: "/pages/user/arbitration/arbitration", // 征信协议


  // 活动
  newSale: "/pages/active/newSale/newSale", // 13活动
  fineSale: "/pages/active/fineSale/fineSale", // 13活动
  numSale: "/pages/active/numSale/numSale", // 13活动
  active13: "/pages/active/active-13/active-13", // 13活动


};
const routes = {
  navigateTo({
    url,
    param
  }) {
    let URL = url

    if (param) {
      URL = url + `?param=${encodeURIComponent(JSON.stringify(param))}`
    }

    const successUrl = [
      "/pages/product/detail/detail",
      "/pages/product/shops/shops",
      "/pages/active/newSale/newSale",
      "/pages/active/fineSale/fineSale",
      "/pages/active/numSale/numSale",
      "/pages/product/products/products",
      "/pages/order/coupons/coupons",
      "/pages/active/hotSale/hotSale"
    ]

    const switchUrl = [
      "/pages/main/home/home",
      "/pages/main/category/category",
      "/pages/main/my/my",
    ]

    //  没有登录
    if (successUrl.includes(url)) {
      console.log("可以通行")
      my.navigateTo({
        url: URL,
        fail: (err) => {
          console.log('navigateTo跳转出错', err)
        },
      })
      return
    }

    if (switchUrl.includes(url)) {
      console.log("可以通行", URL)
      my.switchTab({
        url: URL,
        fail: (err) => {
          console.log('navigateTo跳转出错', err)
        },
      })
      return
    }

    let userInfo = my.getStorageSync({
      key: 'user'
    })

    if (!userInfo.data) {
      my.showToast({
        type: 'exception ',
        content: '你还没有登陆',
        duration: 1000,
      });
      return
    }
    //  登录后   
    my.navigateTo({
      url: URL,
      fail: (err) => {
        console.log('navigateTo跳转出错', err)
      },
    })
  }
}


module.exports = {
  URL,
  routes,
};